# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-jsonm
pkgver=1.0.2
pkgrel=0
_pkgreal=jsonm
pkgdesc="Non-blocking streaming JSON codec"
url="https://erratique.ch/software/jsonm"
arch="all !riscv64 !loongarch64" # ocaml
license="ISC"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-uutf-dev
	"
makedepends="
	$depends_dev
	ocaml
	ocamlbuild
	ocaml-findlib
	ocaml-topkg
	cmd:opam-installer
	"
subpackages="
	$pkgname-dev
	$pkgname-tools
	"
source="$_pkgreal-$pkgver.tar.bz2::https://erratique.ch/software/jsonm/releases/jsonm-$pkgver.tbz"
builddir="$srcdir/$_pkgreal-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	ocaml pkg/pkg.ml build -v \
		--tests "$(want_check && echo true || echo false)"
}

check() {
	ocaml pkg/pkg.ml test -v
}

package() {
	opam-installer -i \
		--prefix="$pkgdir/usr" \
		--libdir="$pkgdir/$_ocamldir" \
		--docdir="$builddir/.omit" \
		$_pkgreal.install
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

tools() {
	pkgdesc="$pkgdesc (command line utilities)"
	depends=

	amove usr/bin
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
0072f5c31080202ed1cb996a8530d72c882723f26b597f784441033f59338ba8c0cbabf901794d5b1ae749a54af4d7ebf7b47987db43488c7f6ac7fe191a042f  jsonm-1.0.2.tar.bz2
"
